package com.lk.ii.controller;

import com.lk.common.utils.security.Md5Utils;
import com.lk.common.core.controller.BaseController;
import com.lk.ii.constant.IiConstants;
import com.lk.ii.domain.*;
import com.lk.ii.service.IIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class SiteController extends BaseController {

    @Autowired
    private IIService iiService;

    @GetMapping({"/", ""})
    public String index(ModelMap mmap) {
        List<IiAdMaterial> indexAdList = iiService.getAdList("index");
        mmap.put("indexAdList", indexAdList);
        List<IiArticle> recommendArticle = iiService.getRecommendArticleList("index_hot_news");
        mmap.put("hotNews", recommendArticle);
        List<IiActivity> hotActivity = iiService.getRecommendActivityList("index_recommend_activities");
        mmap.put("hotActivities", hotActivity);
        List<IiProduct> hotProductList = iiService.getRecommendProductList("index_recommend_products");
        mmap.put("hotProducts", hotProductList);
        List<IiSolution> hotSolutionList = iiService.getRecommendSolutionList("index_recommend_solutions");
        mmap.put("hotSolutions", hotSolutionList);
        List<IiCase> hotCaseList = iiService.getRecommendCaseList("index_recommend_cases");
        mmap.put("hotCases", hotCaseList);
        List<IiResearchReport> hotResearchReportList = iiService.getRecommendResearchReportList("index_recommend_reports");
        mmap.put("hotResearchReports", hotResearchReportList);
        return "site/index";
    }

    @GetMapping({"/news"})
    public String news(ModelMap mmap) {
        List<IiCategory> categories = iiService.getCategoryService().getTypeCategoryList(IiConstants.TYPE_NEWS);
        mmap.put("categories", categories);
        return "site/news";
    }

    @GetMapping({"/news/{id}"})
    public String news_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiArticle iiArticle = iiService.getArticleService().selectIiArticleById(id);
        String sid = Md5Utils.hash(iiArticle.getId().toString() + "|" + iiArticle.getTitle());
        iiArticle.setSid(sid);
        mmap.put("iiArticle", iiArticle);
        IiAuthor iiAuthor = iiService.getAuthorService().selectIiAuthorById(iiArticle.getAuthorId());
        mmap.put("iiAuthor", iiAuthor);
        List<IiArticle> hotArticle = iiService.getRecommendArticleList("news_detail_hot_news");
        mmap.put("hotNews", hotArticle);
        List<IiArticle> recommendArticle = iiService.getRecommendArticleList("news_detail_recommend_news");
        mmap.put("recommendNews", recommendArticle);
        return "site/news_detail";
    }

    @GetMapping({"/video"})
    public String video(ModelMap mmap) {
        List<IiCategory> categories = iiService.getCategoryService().getTypeCategoryList(IiConstants.TYPE_VIDEO);
        mmap.put("categories", categories);
        return "site/video";
    }

    @GetMapping({"/video/{id}"})
    public String video_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiVideo iiVideo = iiService.getVideoService().selectIiVideoById(id);
        String sid = Md5Utils.hash(iiVideo.getId().toString() + "|" + iiVideo.getTitle());
        iiVideo.setSid(sid);
        mmap.put("iiVideo", iiVideo);
        IiAuthor iiAuthor = iiService.getAuthorService().selectIiAuthorById(iiVideo.getAuthorId());
        mmap.put("iiAuthor", iiAuthor);
        List<IiVideo> hotVideo = iiService.getRecommendVideoList("video_detail_recommend_videos");
        mmap.put("hotVideos", hotVideo);
        return "site/video_detail";
    }

    @GetMapping({"/activity"})
    public String activity(ModelMap mmap) {
        return "site/activity";
    }

    @GetMapping({"/activity/{id}"})
    public String activity_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiActivity iiActivity = iiService.getActivityService().selectIiActivityById(id);
        mmap.put("iiActivity", iiActivity);
        List<IiActivity> hotActivity = iiService.getRecommendActivityList("activity_detail_recommend_activities");
        mmap.put("hotActivities", hotActivity);
        return "site/activity_detail";
    }

    @GetMapping({"/encyclopedia"})
    public String encyclopedia(ModelMap mmap) {
        return "site/encyclopedia";
    }

    @GetMapping({"/encyclopedia/{id}"})
    public String encyclopedia_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiEncyclopedia iiEncyclopedia = iiService.getEncyclopediaService().selectIiEncyclopediaById(id);
        mmap.put("iiEncyclopedia", iiEncyclopedia);
        List<IiEncyclopedia> hotIiEncyclopedia = iiService.getRecommendEncyclopediaList("encyclopedia_detail_recommend_encyclopedia");
        mmap.put("hotEncyclopedias", hotIiEncyclopedia);
        return "site/encyclopedia_detail";
    }
   /* *//*百科的模糊查询*//*
    @GetMapping({"/encyclopedia/{name}"})
    public List<Object> encyclopedia2(@PathVariable("name") String name){

        return iiService.getActivityService().selectIiActivityName(name);
    }*/

    @GetMapping({"/product"})
    public String product(ModelMap mmap) {
        return "site/product";
    }

    @GetMapping({"/product/{id}"})
    public String product_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiProduct iiProduct = iiService.getProductService().selectIiProductById(id);
        mmap.put("iiProduct", iiProduct);
        return "site/product_detail";
    }

    @GetMapping({"/solution"})
    public String solution(ModelMap mmap) {
        return "site/solution";
    }

    @GetMapping({"/solution/{id}"})
    public String solution_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiSolution  iiSolution = iiService.getSolutionService().selectIiSolutionById(id);
        mmap.put("iiSolution", iiSolution);
        return "site/solution_detail";
    }

    @GetMapping({"/case/{id}"})
    public String case_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiCase iiCase = iiService.getCaseService().selectIiCaseById(id);
        mmap.put("iiCase", iiCase);
        return "site/case_detail";
    }

    @GetMapping({"/report"})
    public String report(ModelMap mmap) {
        return "site/report";
    }

    @GetMapping({"/report/{id}"})
    public String report_detail(@PathVariable("id") Long id, ModelMap mmap) {
        IiResearchReport iiResearchReport = iiService.getResearchReportService().selectIiResearchReportById(id);
        mmap.put("iiResearchReport", iiResearchReport);
        IiAuthor iiAuthor = iiService.getAuthorService().selectIiAuthorById(iiResearchReport.getAuthorId());
        mmap.put("iiAuthor", iiAuthor);
        return "site/report_detail";
    }

}
